package com.coszero.common.dialog;


import android.app.Activity;
import android.content.DialogInterface;

import com.coszero.ui.dialog.AlertDialog;
import com.coszero.utils.app.AppManager;


/**
 * Desc：
 *
 * @author xmqian
 * Email:xmqian93@163.com
 * Date: 2021/8/20 17:03
 * @version 1
 */
public class CommonDialogView {

    public static void showLoginErrorDialog(String code, String msg) {
        showMsgDialog(msg, "确定", "取消", new DialogClickListener() {
            @Override
            public void doConfirm() {

            }

            @Override
            public void doCancel() {

            }
        });
    }

    public static void showMsgDialog(String msg, String posBtnStr, String negaBtnStr, DialogClickListener listener) {
        Activity activity = AppManager.getAppManager().currentActivity();
        if (activity != null && activity.isFinishing()) {
//            AppUtil.showToast("窗口已关闭");
            return;
        }
        AlertDialog alertDialog = new AlertDialog(activity);
        alertDialog.builder().setTitle("提示").setMsg(msg)
                .setPositiveButton(posBtnStr, v -> listener.doConfirm())
                .setNegativeButton(negaBtnStr, v -> listener.doCancel()).show();
    }

    /**
     * 不需要回应的提醒弹窗
     */
    public static void shotTipDialog(String msg) {
        Activity activity = AppManager.getAppManager().currentActivity();
        if (activity != null && activity.isFinishing()) {
            return;
        }
        androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(activity);
        builder.setTitle("提示").setMessage(msg).setPositiveButton("知道了", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        }).setCancelable(false).create().show();
    }

    public interface DialogClickListener {
        void doConfirm();

        void doCancel();
    }
}
